package gemini.pollux.ui.client.page.navigation.loginwidget;

import gemini.basic.model.User;

import com.google.gwt.event.shared.GwtEvent;

public class LoginEvent extends GwtEvent<LoginHandler> {

	private static Type<LoginHandler> TYPE;
	
	public static Type<LoginHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<LoginHandler>();
		return TYPE;
	}
	
	public enum ForwardType {
		SUCCESS,
		LOGOUT;
	}
	
	public LoginEvent(ForwardType forwardType) {
		super();
		this.setForwardType(forwardType);
	}
	
	private User loggedInUser;
	
	private ForwardType forwardType;

	@Override
	protected void dispatch(LoginHandler handler) {
		if (forwardType.equals(ForwardType.LOGOUT)) {
			handler.onLogout(this);
		} else if (forwardType.equals(ForwardType.SUCCESS)) {
			handler.onSuccess(this);
		} 
	}

	@Override
	public Type<LoginHandler> getAssociatedType() {
		return getType();
	}

	public void setForwardType(ForwardType forwardType) {
		this.forwardType = forwardType;
	}

	public ForwardType getForwardType() {
		return forwardType;
	}

	public void setLoggedInUser(User loggedInUser) {
		this.loggedInUser = loggedInUser;
	}

	public User getLoggedInUser() {
		return loggedInUser;
	}
}
